<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>日期选择</title>
    </head>
    <body>
        <form>
            <script>
                //year select
                document.writeln("<select id='selYear' name='year'>");
                document.writeln("<option selected='selected' value=''>选择年份<\/option>");//document.writeln("<option value=''>选择年份<\/option>");
                for(var i=1900;i<2100;i++){
                    document.writeln("<option value='"+i+"'>"+i+"年<\/option>");
                }
                document.writeln("<\/select>");
                //control month select display
                var selYear=document.getElementById("selYear");
                selYear.selectedIndex=0;
                selYear.onchange=function(){
                    document.getElementById("selMonth").style.display="";
                    //document.getElementById("selMonth").options[0].setAttribute("selected","true");
                    document.getElementById("selMonth").options[0].selected="true";
                    //document.getElementById("selMonth").selectIndex=0;
                }
                //month select
                document.writeln("<select id='selMonth' style='display:none' name='month'>");
                document.writeln("<option selected='selected' value=''>选择月份<\/option>");
                var months=["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"];
                for(var i=0;i<months.length;i++){
                    document.writeln("<option value='"+i+"'>"+months[i]+"<\/option>");
                }
                document.writeln("<\/select>");
                //control month select display
                var selMonth=document.getElementById("selMonth");
                selMonth.selectedIndex=0;
                selMonth.onchange=function(){
                    selMonth.remove(0);
                    var days=[31,28,31,30,31,30,31,31,30,31,30,31];
                    var leapDays=[31,29,31,30,31,30,31,31,30,31,30,31];
                    var currentYear=parseInt(selYear.options[selYear.selectedIndex].value);
                    var currentMonth=parseInt(selMonth.options[selMonth.selectedIndex].value);
                    var selDate=document.getElementById("selDate");
                    selDate.options.length=0;
                    if(currentMonth==1){//判断是否闰年
                        if(isLeapYear(currentYear)){
                            selDate.options[0]=new Option("选择日期");
                            selDate.options[0].value="";
                            for(var i=1;i<=leapDays[currentMonth];i++){
                                selDate.options[i]=new Option(i+"日");
                                selDate.options[i].value=i;
                            }
                        }else{
                            selDate.options[0]=new Option("选择日期");
                            selDate.options[0].value="";
                            for(var i=1;i<=days[currentMonth];i++){
                                selDate.options[i]=new Option(i+"日");
                                selDate.options[i].value=i;
                            }
                        }
                    }else{
                        selDate.options[0]=new Option("选择日期");
                        selDate.options[0].value="";
                            for(var i=1;i<=days[currentMonth];i++){
                                selDate.options[i]=new Option(i+"日");
                                selDate.options[i].value=i;
                            }
                    }
                    selDate.style.display="";
                }
                //date select
                    document.writeln("<select id='selDate' style='display:none' name='day'>");
                    //document.writeln("<option selected='selected' value=''>选择日期<\/option>");
                    document.writeln("<\/select>");
                    //define function isLeapYear
                    function isLeapYear(year){
                        var result=false;
                        if((year%4==0&&year%100!=0)||year%400==0){
                            result=true;
                        }
                        return result;
                    }
                var 
            </script>
            <input type="submit"/>
        </form>
    </body>
</html>